<template>
    <div id="site-inspection" class="w-h-100 pos-r flex-1 apply-container page-public-s" style="box-sizing: border-box;overflow:hidden;">
        <div class="w-h-100 ver-flex pos-a" style="box-sizing: border-box; padding: 6px;">
            <div style="box-sizing: border-box;">
                <el-card shadow="never" :body-style="{ paddingBottom: '0' }">
                    <el-form class="box-f" ref="queryForm" :inline="true">
                        <el-form-item :label="$t('b0t63v7bGsmbXkQdwW4Q0')">
                            <el-select 
                                v-model="searchVal" 
                                multiple
                                collapse-tags
                                class="m-2" 
                                :placeholder="$t('g6AmUBb2H8qwj8DuC0TH')" 
                                @change="searchChange"
                            >
                                <el-option
                                    v-for="item in searchOptions"
                                    :key="item.value"
                                    :label="item.label"
                                    :value="item.value"
                                />
                            </el-select>
                        </el-form-item>
                        <el-form-item>
                            <div class="search-f">
                                <template v-for="(item, index) in searchVal">
                                    <!-- 检查结果 -->
                                    <template v-if="item === '0'">
                                        <div style="padding: 0 10px">
                                            <el-select 
                                                v-model="checkVal" 
                                                filterable 
                                                class="m-2" 
                                                :placeholder="$t('cymLlSzSGvDCuvZqXJgW')" 
                                                @change="acquireChange"
                                                value-key="id"
                                            >
                                                <el-option
                                                    v-for="item in checkPle"
                                                    :key="item.value"
                                                    :label="item.label"
                                                    :value="item.value"
                                                />
                                            </el-select>
                                        </div>
                                    </template>
                                    <!-- 模糊查询 -->
                                    <template v-if="item === '1'">
                                        <div style="padding: 0 10px">
                                            <el-input v-model="blurVal" :placeholder="$t('yeyw245R7a6VYy19Otp1n')" />
                                        </div>
                                    </template>
                                    <!-- 项目名称 -->
                                    <template v-if="item === '2'">
                                        <div style="padding: 0 10px">
                                            <el-select 
                                                v-model="projectVal" 
                                                filterable 
                                                class="m-2" 
                                                :placeholder="$t('bxEXZmbbz9Az6kHFzoId')" 
                                                @change="acquireChange"
                                                value-key="n_Id"
                                            >
                                                <el-option
                                                    v-for="item in projectNam"
                                                    :key="item.value"
                                                    :label="item.v_ItemProjectName"
                                                    :value="item.n_Id"
                                                />
                                            </el-select>
                                        </div>
                                    </template>
                                    <!-- 巡检编号 -->
                                    <template v-if="item === '3'">
                                        <div style="padding: 0 10px">
                                            <el-input v-model="enableVal" :placeholder="$t('ysIavqEMgMswxJan_7gbO')" />
                                            <!-- <el-select 
                                                v-model="enableVal" 
                                                filterable 
                                                class="m-2" 
                                                :placeholder="$t('4qSllUxIkPaA8Rqf3Jg8y')" 
                                                @change="acquireChange"
                                                value-key="id"
                                            >
                                                <el-option
                                                    v-for="item in responsiblePle"
                                                    :key="item.value"
                                                    :label="item.label"
                                                    :value="item.value"
                                                />
                                            </el-select> -->
                                        </div>
                                    </template>
                                    <!-- 时间段查询 -->
                                    <template v-if="item === '4'">
                                        <div style="padding: 0 10px">
                                            <el-date-picker
                                                v-model="timeVal"
                                                type="datetimerange"
                                                range-separator="-"
                                                start-placeholder="开始时间"
                                                end-placeholder="结束时间"
                                                value-format="YYYY-MM-DD HH:mm:ss"
                                            />
                                        </div>
                                    </template>
                                </template>
                            </div>
                        </el-form-item>
                        <el-form-item >
                            <el-button @click='searchClick' type="primary" icon="ele-Search"> {{ $t('a4Uw6qeAZpctNhl3u7Uge') }} </el-button>
                            <el-button @click="resetClick" icon="ele-Refresh"> {{ $t('rxCkXeM2sO75ltcf8JyVj') }} </el-button>
                            <el-button v-if="$hasPer('siteInspection:add')" @click="nodeClick('')" icon="ele-Plus" type="primary"> {{ $t('kfR7oKqGr0sNpRoAhHcM') }} </el-button>
                        </el-form-item>
                    </el-form>
                </el-card>
            </div>

            <div style="box-sizing: border-box;" class="flex-1 pos-r">
                <div class="pos-a w-h-100" style="box-sizing: border-box;">
                    <el-card class="box-card w-h-100" shadow="never" style="margin-top: 16px;">
                        <div style="" class="w-h-100 ver-flex">
                            <div class="flex-1 pos-r">
                                <div class="pos-a w-h-100">

                                    <el-table :data="list" class="w-h-100" style="width: 100%" border v-loading="loading" element-loading-background="rgba(0, 0, 0, 0.5)">
                                        
                                        <el-table-column type="index" :label="$t('3eKEs1bExAXarYpdJemp')" width="55" align="center" :index="indexMethod" />
                                        
                                        <el-table-column min-width="160" :show-overflow-tooltip="true" :label="$t('ysIavqEMgMswxJan_7gbO')"  align="center">
                                            <el-table-column :show-overflow-tooltip="true" min-width="160" align="center">
                                                <template #header>
                                                    <el-input type="text" :placeholder="$t('ysIavqEMgMswxJan_7gbO')" v-model="searchVar.v_SecurityCheckNO" />
                                                </template>
                                                <template #default="scope">
                                                    <span v-if="scope.row.v_SecurityCheckNO">{{ scope.row.v_SecurityCheckNO }}</span>
                                                    <span v-else> - </span>
                                                </template>
                                            </el-table-column>
                                        </el-table-column>

                                        <el-table-column min-width="160" :show-overflow-tooltip="true" :label="$t('7YrNDepF6YGnXofIKj30l')" align="center">
                                            <el-table-column :show-overflow-tooltip="true" min-width="160" align="center">
                                                <template #header>
                                                    <el-input type="text" :placeholder="$t('7YrNDepF6YGnXofIKj30l')" v-model="searchVar.v_JobApplyNO" />
                                                </template>
                                                <template #default="scope">
                                                    <span v-if="scope.row.v_JobApplyNO && scope.row.v_JobApplyNO !== ''">{{ scope.row.v_JobApplyNO }}</span>
                                                    <span v-else>-</span>
                                                </template>
                                            </el-table-column>
                                        </el-table-column>
                                        
                                        <el-table-column min-width="200" :show-overflow-tooltip="true" :label="$t('5Yg118Gq0SphdlJxlLmTo')"  align="center">
                                            <el-table-column :show-overflow-tooltip="true" min-width="200" align="center">
                                                <template #header>
                                                    <el-input type="text" :placeholder="$t('5Yg118Gq0SphdlJxlLmTo')" v-model="searchVar.n_SecurityCheckTimesNO" />
                                                </template>
                                                <template #default="scope">
                                                    <span v-if="scope.row.n_SecurityCheckTimesNO && scope.row.n_SecurityCheckTimesNO !== ''">{{ scope.row.n_SecurityCheckTimesNO }}</span>
                                                    <span v-else>-</span>
                                                </template>
                                            </el-table-column>
                                        </el-table-column>
                                        
                                        <el-table-column min-width="160" :show-overflow-tooltip="true" :label="$t('tvGbL1MehJrp5EtEfWmB')"  align="center">
                                            <el-table-column :show-overflow-tooltip="true" min-width="160" align="center">
                                                <template #header>
                                                    <el-input type="text" :placeholder="$t('tvGbL1MehJrp5EtEfWmB')" v-model="searchVar.v_ProjectName" />
                                                </template>
                                                <template #default="scope">
                                                    <span v-if="scope.row.v_ProjectName && scope.row.v_ProjectName !== ''">{{ scope.row.v_ProjectName }}</span>
                                                    <span v-else>-</span>
                                                </template>
                                            </el-table-column>
                                        </el-table-column>
                                        
                                        <el-table-column min-width="160" :show-overflow-tooltip="true" :label="$t('g9KAsQ73ULwCiJCd4zgLm')" align="center">
                                            <el-table-column :show-overflow-tooltip="true" min-width="160" align="center">
                                                <template #header>
                                                    <el-input type="text" :placeholder="$t('g9KAsQ73ULwCiJCd4zgLm')" v-model="searchVar.v_TeamName" />
                                                </template>
                                                <template #default="scope">
                                                    <span v-if="scope.row.v_TeamName && scope.row.v_TeamName !== ''">{{ scope.row.v_TeamName }}</span>
                                                    <span v-else>-</span>
                                                </template>
                                            </el-table-column>
                                        </el-table-column>
                                        
                                        <el-table-column min-width="160" :show-overflow-tooltip="true" :label="$t('uXzsqojkX5OpKyUYpdTi')"  align="center">
                                            <el-table-column :show-overflow-tooltip="true" min-width="160" align="center">
                                                <template #header>
                                                    <el-input type="text" :placeholder="$t('uXzsqojkX5OpKyUYpdTi')" v-model="searchVar.v_CheckTypeName" />
                                                </template>
                                                <template #default="scope">
                                                    <span v-if="scope.row.v_CheckTypeName && scope.row.v_CheckTypeName !== ''">{{ scope.row.v_CheckTypeName }}</span>
                                                    <span v-else>-</span>
                                                </template>
                                            </el-table-column>
                                        </el-table-column>
                                        
                                        <el-table-column min-width="160" :show-overflow-tooltip="true" :label="$t('cymLlSzSGvDCuvZqXJgW')" align="center">
                                            <el-table-column :show-overflow-tooltip="true" min-width="160" align="center">
                                                <template #header>
                                                    <el-input type="text" :placeholder="$t('cymLlSzSGvDCuvZqXJgW')" v-model="searchVar.c_CheckResult" />
                                                </template>
                                                <template #default="scoped">
                                                    <span v-if="scoped.row.c_CheckResult">{{ scoped.row.c_CheckResult }}</span>
                                                    <span v-else>待处理</span>
                                                </template>
                                            </el-table-column>
                                        </el-table-column>
                                        
                                        <el-table-column min-width="160" prop="v_ThenCheckTypeName" :show-overflow-tooltip="true" :label="$t('ysIavqEMgMswxJan_7gbC')" align="center">
                                            <template #default="scoped">
                                                <el-button v-if="scoped.row.c_CheckResult === 'NG'" @click="ngDetailClick(scoped.row)" text type="warning"> {{ $t('2KyEk7Ir2Lz3bN9ByjSaE') }} </el-button>
                                                <span v-else>-</span>
                                            </template>
                                        </el-table-column>
                                        
                                        <el-table-column width="260" :formatter="formatDate" :show-overflow-tooltip="true" :label="$t('6Ux7qeGToKiSGgcThOtAh')" align="center">
                                            <el-table-column :show-overflow-tooltip="true" width="260" align="center">
                                                <template #header>
                                                    <el-date-picker
                                                        class="set-t"
                                                        v-model="searchVar.d_CheckDate"
                                                        type="datetime"
                                                        value-format="YYYY-MM-DD HH:mm:ss"
                                                        :placeholder="$t('xYKtSx361Hm1x9r3giOx')"
                                                        popper-class="el-date-p"
                                                    >
                                                    </el-date-picker>
                                                </template>
                                                <template #default="scoped">
                                                    <span v-if="scoped.row.d_CheckDate">{{ scoped.row.d_CheckDate }}</span>
                                                    <span v-else>-</span>
                                                </template>
                                            </el-table-column>
                                        </el-table-column>
                                        
                                        <el-table-column min-width="160" :show-overflow-tooltip="true" :label="$t('eFdfElVxdu3C5z7m3i7zk')" align="center">
                                            <template #default="scoped">
                                                <span v-if="scoped.row.v_WorkContent">{{ scoped.row.v_WorkContent }}</span>
                                                <span v-else>-</span>
                                            </template>
                                        </el-table-column>
                                        
                                        <el-table-column min-width="160" :show-overflow-tooltip="true" :label="$t('2FpsMotcKqtxNCxfbXGqq')" align="center">
                                            <template #default="scoped">
                                                <span v-if="scoped.row.v_Weather">{{ scoped.row.v_Weather }}</span>
                                                <span v-else>-</span>
                                            </template>
                                        </el-table-column>
                                        
                                        <el-table-column min-width="160" :show-overflow-tooltip="true" :label="$t('1rj8iDVdCaStJmgRvySfL')" align="center">
                                            <el-table-column :show-overflow-tooltip="true" min-width="160" align="center">
                                                <template #header>
                                                    <el-input type="text" :placeholder="$t('1rj8iDVdCaStJmgRvySfL')" v-model="searchVar.v_SecurityEmpName" />
                                                </template>
                                                <template #default="scoped">
                                                    <span v-if="scoped.row.v_SecurityEmpName">{{ scoped.row.v_SecurityEmpName }}</span>
                                                    <span v-else>-</span>
                                                </template>
                                            </el-table-column>
                                        </el-table-column>
                                        
                                        <el-table-column min-width="160" :show-overflow-tooltip="true" :label="$t('tDapPdoucZRo6G2_1o6pV')" align="center">
                                            <el-table-column :show-overflow-tooltip="true" min-width="160" align="center">
                                                <template #header>
                                                    <el-input type="text" :placeholder="$t('tDapPdoucZRo6G2_1o6pV')" v-model="searchVar.v_CheckEmpName" />
                                                </template>
                                                <template #default="scoped">
                                                    <span v-if="scoped.row.v_CheckEmpName">{{ scoped.row.v_CheckEmpName }}</span>
                                                    <span v-else>-</span>
                                                </template>
                                            </el-table-column>
                                        </el-table-column>
                                        
                                        <!-- <el-table-column min-width="160" :show-overflow-tooltip="true" :label="$t('4qSllUxIkPaA8Rqf3Jg8y')" align="center">
                                            <template #default="scope">
                                                <span v-if="scope.row.n_isValid === 1" style="color: #07AAF9;">{{ $t('iPfonvtxVLm7knSyCsLBo') }}</span>
                                                <span v-else-if="scope.row.n_isValid === 2" style="color: #FF5F33;">{{ $t('tzm8JwYsKnqKoNhheJlJx') }}</span>
                                            </template>
                                        </el-table-column> -->

                                        <el-table-column min-width="160" :show-overflow-tooltip="true" :label="$t('eHdy6iUn3cS1Nqd3eXMnV')" align="center">
                                            <template #default="scope">
                                                <span style="cursor: pointer;" @click="fileClick(scope.row.v_JobFilePath)" v-if="scope.row.v_JobFilePath && scope.row.jobApply.length !==0">{{ $t('2KyEk7Ir2Lz3bN9ByjSaE') }}</span>
                                                <span v-else>{{ $t('tzv7Fao_8LvfFbddIkvDu') }}</span>
                                            </template>
                                        </el-table-column>
                                        
                                        <el-table-column min-width="160" :show-overflow-tooltip="true" prop="v_Remake" :label="$t('9RLaVEiJf1Z1Qv15o6Kll')" align="center">
                                            <template #default="scope">
                                                <span v-if="scope.row.v_Remake">{{ scope.row.v_Remake }}</span>
                                                <span v-else>-</span>
                                            </template>
                                        </el-table-column>
                                        
                                        <el-table-column min-width="160" :show-overflow-tooltip="true" prop="createdTime" :label="$t('xxAj6fsjvIsQrMdlNpolv')" align="center" />
                                        
                                        <el-table-column min-width="160" :show-overflow-tooltip="true" prop="createdUserName" :label="$t('v7AhfaNeGaFoPfZzgpFk')" align="center" />
                                        
                                        <el-table-column min-width="400" :label="$t('liBmO8wb58NMw5HLu9Nf')" align="center" fixed="right">
                                            <template #default="scope">
                                                <el-button v-if="$hasPer('siteInspection:gc')" @click="polClick(scope.row)" class="icon-e" icon="Discount" size="small" text type="warning"> {{ $t('w9KxAyYCobkSVylEmF2nJ') }} </el-button>
                                                <el-button v-if="$hasPer('siteInspection:zyxq')" @click="jobeClick(scope.row)" class="icon-e" icon="Finished" size="small" text type="success"> {{ $t('w9KxAyYCobkSVylEmF3nB') }} </el-button>
                                                <el-button v-if="$hasPer('siteInspection:xjxq')" @click="nodeClickTwo(scope.row)" class="icon-e" icon="ele-View" size="small" text type="primary"> {{ $t('he8D83RdrkLmVr49aJklx') }} </el-button>
                                                <template v-if="$hasPer('siteInspection:edit')">
                                                    <el-button v-if="scope.row.c_CheckResult === ''" @click="nodeClick(scope.row)" class="icon-e" icon="ele-Edit" size="small" text type="primary"> {{ $t('1sDlm0R9C8Y4k6nvtiis') }} </el-button>
                                                    <el-button v-else class="icon-e" icon="ele-Edit" size="small" text type="warning"> {{ $t('dHOWul3YPiJbzLvxQswg') }} </el-button>
                                                </template>
                                                <el-button v-if="$hasPer('siteInspection:del')" @click="deleteHandle(scope.row.n_Id , getData)" class="icon-e" icon="ele-Delete" size="small" text type="danger"> {{ $t('mkwlMbm3qr88f0XxV9Pje') }} </el-button>
                                            </template>
                                        </el-table-column>
                                    
                                    </el-table>
                                </div>
                            </div>
                            <div style="height: 30px;margin-top: 20px;" class="hr-flex-start">
								<el-pagination
									v-model:currentPage="pageNo"
									v-model:page-size="pageSize"
									:total="totalRows"
									:page-sizes="[10, 20, 50, 100]"
									small
									background
									@size-change="handleSizeChange"
									@current-change="handleCurrentChange"
									layout="total, sizes, prev, pager, next, jumper"
									class="w-h-100"
								/>
							</div>
                        </div>
                    </el-card>
                </div>
            </div>
        </div>
        <!-- 新增/编辑 -->
        <add-edit-site-inspection
            :repairInfo="repairInfo"
            :isUseDialog="isUseDialog"
            @updateData="getData"
            @cancelUseClick="cancelUseClick"
            @controlUseClick="controlUseClick"
        />
        <!-- 巡检详情 -->
        <inspection-detail
            :detailType="detailType"
            :formInfo="formInfo"
            :repairInfo="repairInfo"
            :isUseDialog="isDetailDialog"
            @updateData="getData"
            @cancelDetailClick="cancelDetailClick"
        />
        <!-- 巡检过程 -->
        <polling-detail
            :polInfo="polInfo"
            :isUseDialog="isPol"
            @cancelPolClick="cancelPolClick"
        />
        <!-- 作业详情 -->
        <job-detail
            :formInfo="jobFormInfo"
            :repairInfo="jobInfo"
            :isUseDialog="jobDialog"
            @cancelDetailClick="cancelJobClick"
        />
        <VModel
            :fileInfo="fileInfo"
            :isModelDialog="isModelDialog"
            @cancelModelClick="cancelModelClick"
        />
    </div>
</template>
<script lang="ts">
import { defineComponent, ref, onMounted , reactive , toRaw } from 'vue';
import getTableData from '/@/utils/getTableData';
import { SecurityCheckChangePage , SecurityCheckPage , SecurityCheckDelete , projectitemSelector , JobApplyQueryPageList } from '/@/api/sms/sms';
import AddEditSiteInspection from './component/add-edit-site-inspection.vue';
import PollingDetail from './component/polling-detail.vue';
import InspectionDetail from './component/inspection-detail.vue';
import JobDetail from './component/job-detail.vue';
import { ElMessageBox , ElMessage } from 'element-plus';
import useCurrentInstance from '/@/utils/hook/useCurrentInstance';
import VModel from '../components/v-model.vue';
import { i18n } from '/@/locales/i18n';
export default defineComponent( {
    name: 'site-inspection',
    components: {
        AddEditSiteInspection,
        InspectionDetail,
        PollingDetail,
        JobDetail,
        VModel,
    },
    setup(props){
        const { proxy } = useCurrentInstance();
        const $t = proxy.$t;
        
        const isUseDialog = ref() // 新增/编辑弹出框隐藏/显示
        const isDetailDialog = ref(false)
        const repairInfo = ref() // 传递子组件数据
        const formInfo = ref()
        const polInfo = ref() // 巡检过程/整改过程信息数据
        const isPol = ref(false) // 巡检过程/整改过程弹出框
        const detailType = ref() // 详情类型

        const jobFormInfo = ref() // 作业申请详情
        const jobInfo = ref()
        const jobDialog = ref(false)

        const isModelDialog = ref(false);
        const cancelModelClick = () => {isModelDialog.value = false};
        const fileInfo = ref('');

        /*** 查看文件 */
        const fileClick = (val: any) => {
            isModelDialog.value = true;
            let setObj: any = {};
            setObj.titleInfo = $t('eHdy6iUn3cS1Nqd3eXMnV');
            setObj.rectifyListArr = val;
            fileInfo.value = JSON.stringify(setObj);
        }


        /*** ngDetailClick问题详情点击事件 */
        const ngDetailClick = (val:any | object) => {
            console.log(val,'row');
            detailType.value = 'only'
            detailFun(val);
        }

        const searchVar = reactive({
            v_SecurityCheckNO: '',
            v_JobApplyNO: '',
            n_SecurityCheckTimesNO: '',
            v_ProjectName: '',
            v_TeamName: '',
            v_CheckTypeName: '',
            c_CheckResult: '',
            d_CheckDate: '',
            v_SecurityEmpName: '',
            v_CheckEmpName: '',
        });

        // 搜索类
        const checkVal = ref(undefined) // 检查结果
        const blurVal = ref() // 模糊查询
        const projectVal = ref() // 项目查询
        const enableVal = ref() // 是否启用
        const timeVal = ref() // 时间段查询

        const searchOptions = ref([{
            value: '0',
            label: $t('cymLlSzSGvDCuvZqXJgW'),
            vals: checkVal,
        }, {
            value: '1',
            label: $t('3dBd6Gp5MqNm4A5dvcqJ4'),
            vals: blurVal
        }, {
            value: '2',
            label: $t('kJu7Trhi2W73OAVloSf'),
            vals: projectVal
        }, 
        // {
        //     value: '3',
        //     label: $t('4qSllUxIkPaA8Rqf3Jg8y'),
        //     vals: enableVal
        // },  
        {
            value: '3',
            label: $t('ysIavqEMgMswxJan_7gbO'),
            vals: enableVal
        },{
            value: '4',
            label: $t('bxOzlOcGrW1Oanu81ddgi'),
            vals: timeVal
        }]) // 搜索方式

        const searchVal = ref(['0'])
        const transferVal = ref() // 需要查询的值
        const projectNam:any = ref([]) // 项目名称
        let searchObj:any = reactive({
            c_CheckResult: '',
            searchValue: '',
            n_ProjectId: '',
            // n_isValid: '',
            v_JobApplyNO: '',
            startTime: '',
            endTime: '',
        })
        /*** 搜索类型选择事件 searchChange */
        const searchChange = (val:any) => {
            if(val.length === 0){
                checkVal.value = undefined// 检查结果
                blurVal.value = '' // 模糊查询
                projectVal.value = '' // 项目查询
                enableVal.value = '' // 是否启用
                timeVal.value = '' // 时间段查询
            }else{
                let getArr = getArrDifference(val,toRaw(searchOptions.value))
                if(getArr.length !== 0){
                    console.log(getArr,'getArr')
                    getArr.map((i:any) => {
                        toRaw(searchOptions.value)[i].vals.value = ''
                    })
                }
            }
            searchVal.value = val
        }
        /*** getArrDifference 提取两个数组中不同的元素 */
        const getArrDifference = (arr1: any | [] , arr2: any | []) => {
            let getArr = []
            for(let z in arr2){
                getArr.push(z)
            }
            return arr1.concat(getArr).filter((v:any, i:any, arr:any) => {
                return arr.indexOf(v) === arr.lastIndexOf(v)
            })
        }
        /*** acquireChange 搜索下拉框选择的数据 ---- 传给接口数据 */
        const acquireChange = (val:any) => {
            transferVal.value = val
        }
        /*** searchClick 查询按钮 */
        const searchClick = () => {
            // if(checkVal.value !== undefined && checkVal.value !== ''){
            //     searchObj.c_CheckResult = checkVal.value
            // }
            if(checkVal.value !== undefined){
                searchObj.c_CheckResult = checkVal.value
            }
            if(blurVal.value !== undefined && blurVal.value !== ''){
                searchObj.searchValue = blurVal.value
            }
            if(projectVal.value !== undefined && projectVal.value !== ''){
                searchObj.n_ProjectId = projectVal.value
            }
            if(enableVal.value !== undefined && enableVal.value !== ''){
                // searchObj.n_isValid = enableVal.value
                searchObj.V_SecurityCheckNO = enableVal.value
            }
            console.log(toRaw(timeVal.value),'timeVal')
            if(toRaw(timeVal.value) && toRaw(timeVal.value) !== ''){
                searchObj.startTime = toRaw(timeVal.value)[0] 
                searchObj.endTime = toRaw(timeVal.value)[1]
            }else{
                searchObj.startTime = ''
                searchObj.endTime = ''
            }
        }
        /*** resetClick 重置按钮 */
        const resetClick = () => {
            searchObj.c_CheckResult = ''
            searchObj.searchValue = ''
            searchObj.n_ProjectId = ''
            // searchObj.n_isValid = ''
            searchObj.V_SecurityCheckNO = ''
            searchObj.startTime = ''
            searchObj.endTime = ''

            checkVal.value = undefined // 检查结果
            blurVal.value = '' // 模糊查询
            projectVal.value = '' // 项目查询
            enableVal.value = '' // 是否启用
            timeVal.value = '' // 时间段查询
            searchVal.value = ['0']
        }
        // 搜索类

        /*** 截取日期格式方法 */
        const formatDate = (row:any, column:any) => {
          // 获取单元格数据
          let data = row[column.property]
          if(data == $t('utiIUzqSzcKy0QiDc49n')) {
            return '-'
          }else{
            return data
          }
        }

        /*** nodeClick 新增/编辑点击事件 */
        const nodeClick = (val:string | object) => {
            val !== '' ? repairInfo.value = JSON.stringify(toRaw(val)) : repairInfo.value = ''
            isUseDialog.value = true
        }

        /*** nodeClickTwo 危险源详情 */
        const nodeClickTwo = (val:any | object) => {
            detailType.value = 'all'
            detailFun(val);
        }

        /*** detailFun 详情数据函数 */
        const detailFun = (val:any | object) => {
            val !== '' ? repairInfo.value = JSON.stringify(toRaw(val)) : repairInfo.value = ''
            let valInfo = toRaw(val);
            let label = {
                label15: $t('ysIavqEMgMswxJan_7gbO'),
                label16: $t('5Yg118Gq0SphdlJxlLmTo'),
                label1: $t('dong-gong-xiang-mu'),
                label2: $t('jian-cha-bu-men-ban-zu'),
                label3: $t('jian-cha-lei-bie'),
                label4: $t('hou-xu-jian-cha-lei-bie'),
                label5: $t('jian-cha-jie-guo'),
                label6: $t('jian-cha-ri-qi'),
                label7: $t('gong-zuo-nei-rong'),
                label8: $t('tian-qi-qing-kuang'),
                label9: $t('an-quan-yuan'),
                label10: $t('jian-cha-ren'),
                label11: $t('7YrNDepF6YGnXofIKj30l'),
                // label11: $t('shi-fou-qi-yong'),
                label12: $t('bei-zhu'),
                label13: $t('chuang-jian-shi-jian'),
                label14: $t('chuang-jian-ren'),
            }
            let setObj = {
                [label.label15]: valInfo.v_SecurityCheckNO,
                [label.label16]: valInfo.n_SecurityCheckTimesNO,
                [label.label1]: valInfo.v_ProjectName,
                [label.label2]: valInfo.v_TeamName,
                [label.label3]: valInfo.v_CheckTypeName,
                [label.label4]: valInfo.v_ThenCheckTypeName,
                [label.label5]: valInfo.c_CheckResult,
                [label.label6]: valInfo.d_CheckDate && valInfo.d_CheckDate !== $t('utiIUzqSzcKy0QiDc49n') ? valInfo.d_CheckDate : '-',
                [label.label7]: valInfo.v_WorkContent,
                [label.label8]: valInfo.v_Weather,
                [label.label9]: valInfo.v_SecurityEmpName,
                [label.label10]: valInfo.v_CheckEmpName,
                [label.label11]:  valInfo.v_JobApplyNO && valInfo.v_JobApplyNO !=='' ? valInfo.v_JobApplyNO : $t('i9bg9ga34Vp7vSAeG1MlW'),
                [label.label12]: !valInfo.v_Remake ? '-' : valInfo.v_Remake,
                [label.label13]: valInfo.createdTime,
                [label.label14]: valInfo.createdUserName,
            }
            formInfo.value = setObj;
            isDetailDialog.value = true
        }

        /*** jobeClick 作业详情 */
        const jobeClick = (val:string | object) => {
            jobDaetailFun(val);
        }

        /*** cancelJobClick 作业详情关闭事件 */
        const cancelJobClick = () => {
            jobDialog.value = false;
        }

        /*** jobDaetailFun 获取作业申请接口 */
        const jobDaetailFun = async (val:any) => {
            let param:any = {}
            param.pageIndex = 1;
            param.pageSize = 1;
            param.N_Id = toRaw(val).n_JobApply;
            let res:any = await JobApplyQueryPageList(param);
            if(res.success) jobDetailDispose(res.data.rows[0]);
        }

        /*** jobDetailDispose 作业详情数据处理 */
        const jobDetailDispose = (val:any) => {
            val !== '' ? jobInfo.value = JSON.stringify(toRaw(val)) : jobInfo.value = ''
            let statusName = ''
            if(val.n_AuditState === -1) statusName = $t('xNx5qj0Ad0Oxydt0q1C');
            else if(val.n_AuditState === 0) statusName = $t('gf0Sq2nS1hOty874oBt4g');
            else if(val.n_AuditState === 1) statusName = $t('1uO8o9kmpBShOnoFlN');
            else if(val.n_AuditState === 2) statusName = $t('tzuZnLza7bAuCxmnbIFoc');
            else statusName = $t('u9BFyR2tsG3wjB01C77Rw');

            let n_isValidName = ''
            if(val.n_isValid === 1) n_isValidName = $t('iPfonvtxVLm7knSyCsLBo');
            else n_isValidName = $t('tzm8JwYsKnqKoNhheJlJx');
            let label = {
                label1: $t('tvGbL1MehJrp5EtEfWmB'),
                label2: $t('qVn0337gWLy0M0qCFzJ'),
                label15: $t('7YrNDepF6YGnXofIKj30l'),
                label3: $t('xuuQbgKgXbSnhNsF78bC'),
                label4: $t('znlr2HhiXheU4cdB8JdS4'),
                label5: $t('c5NzyFbtc8sW51KvMa9n'),
                label6: $t('uk_220Omr0p3DgKxFxwB4'),
                label7: $t('s4KbtSrTfOzuWyRcHgTxx'),
                label8: $t('0EDVq0EaoQowa5yp4H0'),
                label16: $t('0EDVq0EaoQowa5yp4H1'),
                label9: $t('sfwbsExMM3lGjDuN5zHf'),
                label10: $t('9RLaVEiJf1Z1Qv15o6Kll'),
                label11: $t('xxAj6fsjvIsQrMdlNpolv'),
                label12: $t('m6m2zmeJ3Vdo7p0eHEeUp'),
                label13: $t('hMMqYalIdWhk0McqdxTg'),
                label14: $t('yRc0RHyyMh9Cy0TKyYr'),
            }
            let setObj = {
                [label.label1]: val.v_ProjectName === '' ? '-' : val.v_ProjectName,
                [label.label2]: val.v_JobTypeName,
                [label.label15]: val.v_ApplyNO,
                [label.label3]: val.v_JobAddress,
                [label.label4]: val.v_ApplyContent,
                [label.label5]: val.v_ApplyEmpName,
                [label.label6]: statusName,
                // [label.label7]: val.v_JobFilePath,
                [label.label8]: val.d_JobTime,
                [label.label16]: val.d_IntendedCompletionTime,
                [label.label9]: n_isValidName,
                [label.label10]: val.v_Remake,
                [label.label11]: val.createdTime,
                [label.label12]: val.createdUserName,
                [label.label13]: val.updatedTime ? val.updatedTime : '-',
                [label.label14]: val.updatedUserName ? val.updatedUserName : '-',
            }
            jobFormInfo.value = setObj;
            jobDialog.value = true
        }

        /*** deleteHandle 删除数据事件 */
        const deleteHandle = async (val: String | Number , updateFun: Function) => {
            ElMessageBox.confirm($t('jj0tHyWhJ4Frf44t43S4c'),$t('99FoyBoPtExRdppuYpkx'),
                {
                    confirmButtonText: $t('cpmrq09Mw3tfVmwWGsZzb'),
                    cancelButtonText: $t('wFa44E4Iz025Ha2gYeDop'),
                    type: 'warning',
                }
            )
            .then(async() => {
                let param = {n_Id : val}
                try {
                    let res:any = await SecurityCheckDelete(param)
                    if(res.success){
                        updateFun()
                    }
                } catch (err) { return }
            })
            .catch(() => {
                ElMessage({
                    type: 'info',
                    message: $t('ummczgwDCP3jaIVczZic'),
                })
            })
        }

        /*** cancelUseClick 取消事件 */
        const cancelUseClick = () => {
            isUseDialog.value = false
        }

        /*** controlDetailClick 详情取消事件 */
        const cancelDetailClick = () => {
            isDetailDialog.value = false
        }

        /*** controlUseClick 提交事件 */
        const controlUseClick = () => {
            isUseDialog.value = false
        }

        onMounted(() => {
            GetInfo()
        })
        /*** GetInfo 获取所有信息 */
        const GetInfo = async () => {
            // 项目列表
            let projectRes:any = await projectitemSelector()
            if(projectRes.success){
                projectNam.value = projectRes.data
            }
        }

        /*** polClick 打开巡检过程/整改过程事件 */
        const polClick = async (val:any) => {
            let polRes:any = await SecurityCheckPage({v_SecurityCheckNO: val.v_SecurityCheckNO});
            let polData:any = {};
            polData.des = '巡检过程';
            polData.polHeader = [
                {label: $t('ysIavqEMgMswxJan_7gbO'),prop: 'v_SecurityCheckNO',width: '160',inx: 0},
                {label: $t('5Yg118Gq0SphdlJxlLmTo'),prop: 'n_SecurityCheckTimesNO',width: '200',inx: 1},
                {label: $t('tvGbL1MehJrp5EtEfWmB'),prop: 'v_ProjectName',width: '180',inx: 2},
                {label: $t('g9KAsQ73ULwCiJCd4zgLm'),prop: 'v_TeamName',width: '180',inx: 3},
                {label: $t('uXzsqojkX5OpKyUYpdTi'),prop: 'v_CheckTypeName',width: '160',inx: 4},
                {label: $t('gGgLWjwiZpOzA_8sGj'),prop: 'v_ThenCheckTypeName',width: '160',inx: 5},
                {label: $t('cymLlSzSGvDCuvZqXJgW'),prop: 'c_CheckResult',width: '160',inx: 6},
                {label: $t('6Ux7qeGToKiSGgcThOtAh'),prop: 'd_CheckDate',width: '160',inx: 7},
                {label: $t('eFdfElVxdu3C5z7m3i7zk'),prop: 'v_WorkContent',width: '160',inx: 8},
                {label: $t('2FpsMotcKqtxNCxfbXGqq'),prop: 'v_Weather',width: '160',inx: 9},
                {label: $t('1rj8iDVdCaStJmgRvySfL'),prop: 'v_SecurityEmpName',width: '160',inx: 10},
                {label: $t('tDapPdoucZRo6G2_1o6pV'),prop: 'v_CheckEmpName',width: '160',inx: 11},
                {label: $t('7YrNDepF6YGnXofIKj30l'),prop: 'v_JobApplyNO',width: '160',inx: 12},
                {label: $t('9RLaVEiJf1Z1Qv15o6Kll'),prop: 'v_Remake',width: '160',inx: 13},
                {label: $t('xxAj6fsjvIsQrMdlNpolv'),prop: 'createdTime',width: '160',inx: 14},
                {label: $t('v7AhfaNeGaFoPfZzgpFk'),prop: 'createdUserName',width: '160',inx: 15},
            ];
            const polRows = polRes.data.rows;
            await polRows.map(async (i:any) => {
                i.v_JobApplyNO && i.v_JobApplyNO !== '' ? i.v_JobApplyNO = i.v_JobApplyNO : i.v_JobApplyNO = $t('i9bg9ga34Vp7vSAeG1MlW');
                i.v_Remake && i.v_Remake !== '' ? i.v_Remake = i.v_Remake : i.v_Remake = '-';
                i.d_CheckDate && i.d_CheckDate !== $t('utiIUzqSzcKy0QiDc49n') ? i.d_CheckDate = i.d_CheckDate : i.d_CheckDate = '-';
                const res = await getAbarbeitungFun(i.n_Id);
                i.s_family = res;
            });

            polData.polBody = polRows;
            polInfo.value = polData;
            isPol.value = true;
        }

        /*** getAbarbeitungFun 获取整改记录数据 */
        const getAbarbeitungFun = async(id:any) => {
            let getInfo = []
            let meaRes:any = await SecurityCheckChangePage({N_CheckId: id,PageNum: 1, PageSize: 100});
            if(meaRes.success) getInfo = meaRes.data.rows;
            return getInfo;
        }

        /*** cancelPolClick 巡检过程/整改过程关闭事件 */
        const cancelPolClick = () => {
            isPol.value = false;
        }

        return {
            ...getTableData(SecurityCheckPage,{},searchObj),
            isUseDialog,
            isDetailDialog,
            cancelUseClick,
            controlUseClick,
            cancelDetailClick,
            nodeClick,
            repairInfo,
            deleteHandle,

            // 搜索类
            searchVal,
            transferVal,
            resetClick,
            searchClick,
            searchChange,
            acquireChange,
            projectNam, // 项目名称
            searchOptions,
            responsiblePle: [
                { label: $t('iPfonvtxVLm7knSyCsLBo') , value: 1 },
                { label: $t('tzm8JwYsKnqKoNhheJlJx') , value: 2 },
            ], // 是否启用
            checkPle: [
                {label: $t('w9KxAyYCobkSVylEmF2nH'), value: 'TODO'},
                {label: 'OK', value: 'OK'},
                {label: 'NG', value: 'NG'}
            ],
            checkVal, // 检查结果
            blurVal, // 模糊查询
            projectVal, // 项目查询
            enableVal, // 是否启用
            timeVal, // 时间段查询
            // 搜索类

            nodeClickTwo,
            formatDate,
            formInfo,

            polInfo,
            isPol,
            cancelPolClick,
            polClick,

            ngDetailClick,
            detailType,
            jobeClick,

            jobFormInfo,
            jobInfo,
            jobDialog,
            cancelJobClick,
            searchVar,

            isModelDialog,
            cancelModelClick,
            fileInfo,
            fileClick,
        }
    },
} )
</script>
<style lang="scss"> @import '../style/public.scss'; </style>
<style scoped lang="scss">
    #site-inspection {
        .box-f{
            :deep(.el-form-item__label){
                padding: 0;
            }
        }
        :deep(.el-card__body) {
            height: 100%;
        }
        :deep(.el-card){
            border: none !important;
        }
        ul {

            list-style: none;

            li {
                cursor: pointer;

                &:hover {
                    color: red;
                }
            }
        }
        .search-f{
            display: flex;
            flex-direction: row;
            justify-content: flex-start;
            align-items: center;
        }
        .icon-e{
            :deep(.el-icon){
                margin-right: 0px!important;
            }
        }
    }
</style>